package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.RscAdjustContDao;
import com.fdb.efp.nls.service.domain.RscAdjustCont;
import com.fdb.efp.nls.service.facade.RscAdjustContService;
import com.fdb.efp.nls.service.vo.RscAdjustContVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 风险分类调整合同表				<p>
 * @author chenqm1
 * @date 2018-05-07
 */
@Service("rscAdjustContService")
public class RscAdjustContServiceImpl implements RscAdjustContService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(RscAdjustContServiceImpl.class);

	@Autowired
	private RscAdjustContDao rscAdjustContDao;
	
	/**
	 * 新增操作
	 */
	public int insertRscAdjustCont(List<RscAdjustContVO> inRscAdjustContVo) {
		logger.debug("当前新增数据为:"+ inRscAdjustContVo.toString());
		int num = 0;
		try {
//			RscAdjustCont rscAdjustCont = new RscAdjustCont();
//			beanCopy(inRscAdjustContVo, rscAdjustCont);
			num = rscAdjustContDao.insertRscAdjustCont(inRscAdjustContVo);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 根据客户号，担保方式删除操作
	 */
	public int deleteByPk(RscAdjustContVO inRscAdjustContVo) {
		logger.debug("当前删除数据条件为:"+ inRscAdjustContVo);
		int num = 0;
		try {
			RscAdjustCont rscAdjustCont = new RscAdjustCont();
			beanCopy(inRscAdjustContVo, rscAdjustCont);
			num = rscAdjustContDao.deleteByPk(rscAdjustCont);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inRscAdjustContVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 批量更新操作
	 */
	public int updateByPk(RscAdjustContVO inRscAdjustContVo) {
		logger.debug("当前修改数据为:"+ inRscAdjustContVo.toString());
		int num = 0;
		try {
			RscAdjustCont rscAdjustCont = new RscAdjustCont();
			beanCopy(inRscAdjustContVo, rscAdjustCont);
			num = rscAdjustContDao.updateByPk(rscAdjustCont);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inRscAdjustContVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 双主键更新操作
	 */
	public int updateByTaskNo(RscAdjustContVO inRscAdjustContVo) {
		logger.debug("当前修改数据为:"+ inRscAdjustContVo.toString());
		int num = 0;
		try {
			RscAdjustCont rscAdjustCont = new RscAdjustCont();
			beanCopy(inRscAdjustContVo, rscAdjustCont);
			num = rscAdjustContDao.updateByTaskNo(rscAdjustCont);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inRscAdjustContVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public RscAdjustContVO queryByPk(RscAdjustContVO inRscAdjustContVo) {
		
		logger.debug("当前查询参数信息为:"+ inRscAdjustContVo);
		try {
			RscAdjustCont queryRscAdjustCont = new RscAdjustCont();
			beanCopy(inRscAdjustContVo, queryRscAdjustCont);
			RscAdjustCont queryRslRscAdjustCont = rscAdjustContDao.queryByPk(queryRscAdjustCont);
			if (Objects.nonNull(queryRslRscAdjustCont)) {
				RscAdjustContVO outRscAdjustContVo = beanCopy(queryRslRscAdjustCont, new RscAdjustContVO());
				logger.debug("当前查询结果为:"+ outRscAdjustContVo.toString());
				return outRscAdjustContVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RscAdjustContVO> queryAllOwner(RscAdjustContVO rscAdjustContVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<RscAdjustContVO> list = null;
		try {
			List<RscAdjustCont> rscAdjustConts = rscAdjustContDao.queryAllOwnerByPage(rscAdjustContVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ rscAdjustConts.size());
			pageSet(rscAdjustConts, rscAdjustContVo);
			list = (List<RscAdjustContVO>) beansCopy(rscAdjustConts, RscAdjustContVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RscAdjustContVO> queryAllCurrOrg(RscAdjustContVO rscAdjustContVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<RscAdjustCont> rscAdjustConts = rscAdjustContDao.queryAllCurrOrgByPage(rscAdjustContVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+rscAdjustConts.size());
		List<RscAdjustContVO> list = null;
		try {
			pageSet(rscAdjustConts, rscAdjustContVo);
			list = (List<RscAdjustContVO>) beansCopy(rscAdjustConts, RscAdjustContVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RscAdjustContVO> queryAllCurrDownOrg(RscAdjustContVO rscAdjustContVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<RscAdjustCont> rscAdjustConts = rscAdjustContDao.queryAllCurrDownOrgByPage(rscAdjustContVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ rscAdjustConts.size());
		List<RscAdjustContVO> list = null;
		try {
			pageSet(rscAdjustConts, rscAdjustContVo);
			list = (List<RscAdjustContVO>) beansCopy(rscAdjustConts, RscAdjustContVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	@Override
	public int deleteByNo(String taskNo) {
		logger.debug("当前删除数据条件为:"+ taskNo);
		int num = 0;
		try {
			RscAdjustCont rscAdjustCont = new RscAdjustCont();
			beanCopy(taskNo, rscAdjustCont);
			num = rscAdjustContDao.deleteByNo(taskNo);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ taskNo +"删除的数据条数为"+ num);
		return num;
	}

	@Override
	public List<RscAdjustContVO> queryAllOwnerByPageCusId(RscAdjustContVO rscAdjustContVo) {
		logger.debug("当前查询数据信息的参数信息为:");
		List<RscAdjustContVO> list = null;
		try {
			List<RscAdjustCont> rscAdjustConts = rscAdjustContDao.queryAllOwnerByPageCusId(rscAdjustContVo);
			logger.debug("当前查询数据信息的结果集数量为:"+ rscAdjustConts.size());
			pageSet(rscAdjustConts, rscAdjustContVo);
			list = (List<RscAdjustContVO>) beansCopy(rscAdjustConts, RscAdjustContVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

	//判断该合同号是否处于已通过
	@Override
	public List<String> queryContNo() {
		List<String> list  = rscAdjustContDao.queryContNo();
		logger.debug("当前查询数据信息的参数信息为:"+list.size());
		return list;
	}

	
}
